<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2019-06-28
  Time: 9:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="true" %>
<%
    String pash = request.getContextPath();
    String basepash = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + pash + "/";
%>
<html>
<head>
    <base href="<%=basepash%>">
    <%@include file="/publs.jsp"%>
    <title>Title</title>
    <script>
        var cxk="<%=request.getContextPath()%>";
    </script>
</head>
<body>
<div id="root">
    <i-button style="margin: 20px" type="primary" @click="luru">录入退货单</i-button>

    <Modal :mask-closable="false" v-model="lurutuihuodan"  title="退货" width="80%">
        <i-form :inline="true" :label-width="80">
            <form-item label="姓名">
                <i-input @on-change="onXingMing" @on-blur="onXingMings" v-model="namessssss"></i-input>
            </form-item>
            <form-item label="药店名称">
                <i-select :disabled="disabledsss" v-model="yaodian" style="width: 120px">
                    <i-option v-for="item in selevalue" :value="item.userid">{{item.mendian}}</i-option>
                </i-select>
            </form-item>
            <i-button type="primary" @click="tuihuoselect">查询</i-button>
        </i-form>
        <i-table height="550" :data="orderData" :columns="orderColumns"  border>
                <template slot="operation" slot-scope="{row}">
                    <%--@click="searchDetails(row)"--%>
                        <%--@on-row-dblclick="searchDetails(row)"--%>
                    <i-button type="info" icon="md-search"  @click="searchDetails(row)" title="选择性退货">查看详情</i-button>
                </template>
        </i-table>
    </Modal>


    <Modal :mask-closable="false" v-model="tetailsModel" title="销售订单详情" width="850" @on-ok="dingdanxainxaingqing">
        <Divider orientation="left">请说明理由</Divider>
        <i-input type="textarea" v-model="shuomingdeliyou"></i-input>
        <i-table height="300px"  @on-selection-change="onselectchaen" :data="detailsData" :columns="detailsColumns">
            <template slot="numbers" slot-scope="{row,index}">
                <%--<span style="font-size: 12px">{{row.number}}</span>--%>
                    <%--"--%>
                <Input-Number v-model="row.number" @on-change="goumaidezongshu(row,index)" :min="1"></Input-Number>
            </template>
        </i-table>
    </Modal>




    <modal  v-model="detailsModelysy" title="订单详情" width="850">
        <i-table :data="detailsDataysy" :columns="detailsColumnsysy"></i-table>
    </modal>


    <i-table  style="margin: 20px" :data="orderDataysy" :columns="orderColumnsysy"  @on-row-dblclick="searchDetailsysy">
        <%--<template slot="operationysy" slot-scope="{row}">--%>
            <%--<i-button type="info" icon="md-search"  @click="searchDetailsysy(row)">查看详情</i-button>--%>
        <%--</template>--%>
    </i-table>




</div>
<script>
    let _this = null;
    new Vue({
        el:"#root",
        data:{
            orderDataysy:[],
            orderColumnsysy:[
                {title:"编号",key:"id"},
                {title:"订单号",key:"orideridid"},
                {title:"退货人",key:"goumairen"},
                {title:"退货公司",key:"mendinans"},
                {title:"退货时间",key:"goumaishijian"},
                // {title:"操作",slot:"operationysy"}
            ],
            detailsDataysy:[],
            detailsColumnsysy: [
                {title:"编号",key:"id",sortable: true},
                {title:"药品编号",key:"drugsid",sortable: true},
                {title:"数量",key:"number"},
                {title:"价格/元",key:"prices"},
                // {title:"合计/元",render(h,{row}){
                //         return h("span",row.number*row.prices)
                //     }},
                {title:"退货时间",key:"atime",sortable: true}
            ],
            lurutuihuodan:false,
            selevalue:[],
            disabledsss:true,
            orderData:[],
            namessssss:"",
            shuomingdeliyou:"",
            yaodian:0,
            orderColumns:[
                {title:"编号",key:"id"},
                {title:"订单号",key:"orideridid",sortable: true},
                {title:"购买人",key:"goumairen"},
                {title:"购买公司",key:"mendinans"},
                {title:"购买时间",key:"goumaishijian",sortable: true},
                {title:"操作",slot:"operation"}
            ],
            detailsModel:false,
            detailsModelysy:false,
            detailsData:[],
            tetailsModel:false,
            detailsColumns: [
                {type:"selection",width:"50"},
                {title:"编号",key:"id",sortable: true},
                {title:"药品编号",key:"drugsid"},
                {title:"数量",slot:"numbers",sortable: true},
                {title:"价格/元",key:"price"},
                {title:"购买时间",key:"atime",sortable: true}

                // {title:"合计/元",render(h,{row}){
                //         return h("span",row.number*row.price)
                //     }},
            ],
            selectionselection:[]
        },
        methods:{
            luru(){
                this.namessssss = "";
                this.yaodian = "";
                this.selectionselection = [];
                this.lurutuihuodan = true;
            },
            onXingMing(){
                this.yaodian = "";
                this.selevalue = [];
            },
            onXingMings(){
                if(this.namessssss!=null||this.namessssss!=""){
                    this.disabledsss = false;
                }
                this.seras();
            },
            seras(){
                axios.get("/kuhu/select?pageNo=0&pageSize=999999999&name="+this.namessssss).then(({data})=>{
                    this.selevalue = data.obj.list;
                })
            },
            tuihuoselect(){
                    // let name1 = "";//购买人
                    // let name3 = "";//购买公司id
                    let name4 = "购买";//状态
                    let name2 = "";
                    axios.get(`${cxk}/zOnInSearch/searchOrder?name1=${this.namessssss}&name2=${name2}&name3=${this.yaodian}&name4=${name4}`)
                        .then(({data})=>{
                            this.orderData = data.obj;
                        })
            },
            tuihuoselectsssssssss(){
                // let name1 = "";//购买人
                // let name3 = "";//购买公司id
                let name4 = "";//状态
                let name2 = "";
                axios.get(`${cxk}/zOnInSearch/searchOrder?name1=${this.namessssss}&name2=${name2}&name3=${this.yaodian}&name4=${name4}`)
                    .then(({data})=>{
                        this.orderData = data.obj;
                    })
            },
            searchDetails(row){
                console.log(1)
                this.tetailsModel=true
                axios.post(`${cxk}/zOnInSearch/searchDetails?orderIds=${row.id}`)
                    .then(({data})=>{
                        this.detailsModel = true;
                        this.detailsData = data.obj;
                    })
            },
            goumaidezongshu(row,index){
                this.detailsData[index].number = row.number;
                // row.number = row.number;
                // if(row.jianumber>=row.number){
                //     iview.Message.warning("当前总数量为:"+row.number);
                // }
                // row.number = row.jianumber;
            },
            onselectchaen(selection){
                this.selectionselection = selection;
            },
            dingdanxainxaingqing(){
                // if(this.name1==null){
                //     iview.Message.warning("退货失败，请填写姓名。");
                //     return;
                // }
                // if(this.name3==null){
                //     iview.Message.warning("退货失败，请填写公司。");
                //     return;
                // }
                let dindnid = 0;
                axios.get("/Tuihuoorder?gouMaiRen="+this.namessssss+"&gouMaiGongSi="+this.yaodian+"&tuihuoxinxi="+this.shuomingdeliyou)
                    .then(({data})=>{
                        let a = {};
                        for (let i = 0; i < this.selectionselection.length; i++) {
                            Object.assign(this.selectionselection[i],{Orderid:data.msg})
                            console.log(this.selectionselection[i].number)
                            axios.post("/Tuihuoorderdingdan",this.selectionselection[i]).then(({data})=>{
                                this.assss = 1;
                            })
                        }
                        if(this.assss!=0){
                            this.searchAllysy();
                            iview.Message.warning("退货成功!")
                        }
                    })
            },
            searchAllysy(){
                let name1 = "";//购买人
                let name2 = "";//随机数
                let name3 = "";//购买公司id
                let name4 = "退货";//状态
                axios.get(`${cxk}/zOnInSearch/searchOrder?name1=${name1}&name2=${name2}&name3=${name3}&name4=${name4}`)
                    .then(({data})=>{
                        this.orderDataysy = data.obj;
                    })
            },
            searchDetailsysy(row){
                this.tetailsModelysy=true
                axios.post(`${cxk}/zOnInSearch/searchDetails?orderIds=${row.id}`)
                    .then(({data})=>{
                        this.detailsModelysy = true;
                        this.detailsDataysy = data.obj;
                    })
            }
        },
        mounted(){
            this.searchAllysy();
        },
        created(){
            _this = this;
        }
    })
</script>
</body>
</html>
